package com.youlu.campus.web.wechat;

import com.alibaba.fastjson.JSON;
import com.youlu.campus.entity.VO.req.WechatWriteOffReq;
import com.youlu.campus.service.account.WechatWriteOffService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 用户注销
 */
@Slf4j
@RestController
public class WechatWriteOffController {
    @Autowired
    WechatWriteOffService wechatWriteOffService;

    @PostMapping("/mini-app/account/write-off")
    public QResult writeOff(@RequestBody WechatWriteOffReq req) {
        log.info(":>>> 开始注销账户:{}", JSON.toJSON(req));
        req.setUserId(RequestContext.getUserId());
        req.setPlatform(RequestContext.getCurPlatform());
        req.setOpenId(RequestContext.getCurPlatform());
        req.setAppId(RequestContext.getAppId());
        req.setSystemAppId(req.getSystemAppId());
        req.setDate(new Date());
        switch (req.getType()) {
            case "account":
                return QResult.success(wechatWriteOffService.writeOff(req));
            case "activity":
                return QResult.success(wechatWriteOffService.writeOffActivity(req));
            default:
                return QResult.success("de");

        }
    }
}
